<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class changepass extends CI_Controller {
	var $data;
	public function __construct()
	{
		parent::__construct();		
		$this->load->library('session');
		$this->load->model('model_changepass');
		$this->data['title'] = 'Change Password';
	}
	
	public function index()
	{

		$check = $this->session->userdata('CHECK_LOGIN');
		if($check==true){
			redirect(base_url().'dashboard/', 'refresh');
		}else{
			$this->view();
		}
		
	}

	public function view(){
		$key 		=@trim($_GET["key"]);
		$result = $this->model_changepass->selectExists(array('col'=>'mb_key_forget','val'=>$key));
		if(count($result)>0 && isset($key) && $key!=""){
			if(isset($_POST["submit"])){
				$password 	=trim($_POST["password"]);			
				if(strlen($password)>2){
					$this->model_changepass->update(array('key'=>$key,'password'=>md5($password)));
					$this->data['msg']="Change password success!";
					$this->data['st']=true;	
				}else{
					$this->data['msg']="Password length more than 3 character!.";
				}
			}		
				$this->data['block']=false;		
		}else{
		
			$this->data['msg']="Key false!.";
			}		

		$this->load->view('changepass', $this->data);


	}
}